package soccer.stats

class TeamInfoUrlController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [teamInfoUrlInstanceList: TeamInfoUrl.list(params), teamInfoUrlInstanceTotal: TeamInfoUrl.count()]
    }

    def create = {
        def teamInfoUrlInstance = new TeamInfoUrl()
        teamInfoUrlInstance.properties = params
        return [teamInfoUrlInstance: teamInfoUrlInstance]
    }

    def save = {
        def teamInfoUrlInstance = new TeamInfoUrl(params)
        if (teamInfoUrlInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), teamInfoUrlInstance.id])}"
            redirect(action: "show", id: teamInfoUrlInstance.id)
        }
        else {
            render(view: "create", model: [teamInfoUrlInstance: teamInfoUrlInstance])
        }
    }

    def show = {
        def teamInfoUrlInstance = TeamInfoUrl.get(params.id)
        if (!teamInfoUrlInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), params.id])}"
            redirect(action: "list")
        }
        else {
            [teamInfoUrlInstance: teamInfoUrlInstance]
        }
    }

    def edit = {
        def teamInfoUrlInstance = TeamInfoUrl.get(params.id)
        if (!teamInfoUrlInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), params.id])}"
            redirect(action: "list")
        }
        else {
            return [teamInfoUrlInstance: teamInfoUrlInstance]
        }
    }

    def update = {
        def teamInfoUrlInstance = TeamInfoUrl.get(params.id)
        if (teamInfoUrlInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (teamInfoUrlInstance.version > version) {

                    teamInfoUrlInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl')] as Object[], "Another user has updated this TeamInfoUrl while you were editing")
                    render(view: "edit", model: [teamInfoUrlInstance: teamInfoUrlInstance])
                    return
                }
            }
            teamInfoUrlInstance.properties = params
            if (!teamInfoUrlInstance.hasErrors() && teamInfoUrlInstance.save(flush: true)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), teamInfoUrlInstance.id])}"
                redirect(action: "show", id: teamInfoUrlInstance.id)
            }
            else {
                render(view: "edit", model: [teamInfoUrlInstance: teamInfoUrlInstance])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), params.id])}"
            redirect(action: "list")
        }
    }

    def delete = {
        def teamInfoUrlInstance = TeamInfoUrl.get(params.id)
        if (teamInfoUrlInstance) {
            try {
                teamInfoUrlInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), params.id])}"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), params.id])}"
                redirect(action: "show", id: params.id)
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teamInfoUrl.label', default: 'TeamInfoUrl'), params.id])}"
            redirect(action: "list")
        }
    }
}
